package v1.chapter12.dialog;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class DialogFrame extends JFrame {
	private static final int DEFAULT_WIDTH = 300;
	private static final int DEFAULT_HEIGHT = 200;
	private AboutDialog dialog;

	public DialogFrame() {
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu fileMenu = new JMenu("File");
		menuBar.add(fileMenu);

		JMenuItem aboutItem = new JMenuItem("About");
		aboutItem.addActionListener(event -> {
			if (dialog == null)
				dialog = new AboutDialog(DialogFrame.this);
			dialog.setVisible(true);
		});
		fileMenu.add(aboutItem);

		JMenuItem exitItem = new JMenuItem("Exit");
		exitItem.addActionListener(event->System.exit(0));
		fileMenu.add(exitItem);
	}
}
